package com.yztc.xiami_app.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;

import java.io.IOException;
import java.io.InputStream;

public class SharedPrefrencesHelper {

    private static final String BG_PIC_PATH = "bg_path";
    private static final String CITY_NAME = "city";
    private SharedPreferences mPreferences = null;
    private Editor mEditor = null;

    public SharedPrefrencesHelper(Context context) {
        mPreferences = context.getSharedPreferences("info_app", Context.MODE_PRIVATE);
        mEditor = mPreferences.edit();
    }

    /**
     * 保存背景皮肤图片的地址
     */
    public void saveBgPath(String path) {
        mEditor.putString(BG_PIC_PATH, path);
        mEditor.commit();
    }

    public void saveCity(String city) {
        mEditor.putString(CITY_NAME, city);
        mEditor.commit();
    }

    public String getCity() {
        return mPreferences.getString(CITY_NAME, "北京");
    }


    /*public Drawable getDrawableFromAssets(Context context, String path) {
        AssetManager am = context.getAssets();
        InputStream is = null;
        try {
            is = am.open("bgs/" + path);
            Bitmap bitmap = BitmapFactory.decodeStream(is);
            Drawable drawable = new BitmapDrawable(bitmap);
            return drawable;
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return null;
    }*/
}
